package com.mb.mp.controller;

import com.mb.common.controller.BaseController;
import com.mb.common.utils.PageUtils;
import com.mb.common.utils.Query;
import com.mb.common.utils.R;
import com.mb.mp.domain.MpSysConfigDO;
import com.mb.mp.service.ISysParamService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 王源
 * @program mp-parent
 * @description 品牌库未完成
 * @date 2018-09-04 16:44
 **/
@Controller
@RequestMapping("/mp/sysParam")
public class SysParamController extends BaseController{
    private static final Logger logger = LoggerFactory.getLogger(SysParamController.class);

    @Autowired
    private ISysParamService sysParamService;

    @GetMapping("/index")
    String index(){
        return "/mp/sys_param_list";
    }


    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        Query query = new Query(params);
        List<MpSysConfigDO> list = sysParamService.queryList(query);
        int total = sysParamService.count(query);
        PageUtils pageUtils = new PageUtils(list, total);
        return pageUtils;
    }

    @GetMapping("/edit/{id}")
    String edit(@PathVariable("id") Long id, Model model){
        MpSysConfigDO sysConfig = sysParamService.getSysConfig(id);
        model.addAttribute("sysConfig",sysConfig);
        return "/mp/sys_param_add";
    }


    @ResponseBody
    @PostMapping("/update")
    public R update(MpSysConfigDO sysConfigDO) {
        int result = sysParamService.updateSysConfig(sysConfigDO);
        if(result != 0){
            return R.ok();
        }else{
            return R.error(1,"参数修改失败，请联系管理员");
        }
    }



}
